local util = require "util"

local t = {}
local minutes = 1
local seconds = 0
local gameTimer = nil

t.update = function() end

t.timeUp = function() -- default function called on time up
	print ("Time up (default)")
end

t.updateTimer = function()

	seconds = seconds - 1
	if seconds < 0 then
		minutes = minutes - 1
		if minutes < 0 then
			t.timeUp()
			minutes = 0
			seconds = 0
			util.timerCancel(gameTimer)
			return
		end
		seconds = 59
	end
	
	t.update(minutes,seconds)
end

t.willEnterScene = function()
	print ("starting timer")
	gameTimer = timer.performWithDelay(1000, t.updateTimer, 0)
	t.updateTimer()
end

t.exitScene = function()
	print ("cancelling timer")
	timer.cancel(gameTimer)
end

return t